package arkanoid.components.ball;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TimerListener implements ActionListener {
	
	private int remainingSeconds;
	private Ball ball;
	
	public TimerListener(int duration, Ball ball) {
		this.setRemainingSeconds(duration);
		this.setBall(ball);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		this.setRemainingSeconds(this.getRemainingSeconds() - 1);
		if(this.getRemainingSeconds() == 0) {
			this.getBall().setState(new DisattachedNormalBall());
			this.getBall().changeColor(Color.getHSBColor(0.56f, 1.0f, 0.8f));
		}
	}
	
	
	

	public int getRemainingSeconds() {
		return remainingSeconds;
	}

	public void setRemainingSeconds(int remainingSeconds) {
		this.remainingSeconds = remainingSeconds;
	}

	public Ball getBall() {
		return ball;
	}

	public void setBall(Ball ball) {
		this.ball = ball;
	}
}
